*****Conscription and Military Service: Do They Result in Future Violent and Non-Violent Incarcerations and Recidivism?  Wang, Flores-Lagunes 2020*****
****This do-file prints the results for Figure 4 and Figure 5
clear all
cd "C:\Users\xinto\Dropbox\Vietnam Veteran Paper\Crime Paper\2020 JHR Data\9. Figure 4 and Figure 5"
set matsize 1000
program drop _all
qui do CLR_01272015.ado  
qui do mcholx_01272015.ado

global outcomes1="currentViolent  violent_desistence "

global outcomes2="nonviolent_new nonviolent_desistance"

global outcomes3="currentViolent nonviolent_new violent_desistence nonviolent_desistance"

/*Section 1: The following program will use the bootstrapped bounds estimates files 
  to obtain the CLR confidence intervals and the p-value for the null of the bounds
  including zero*/ 
local i=1

foreach outcome in $outcomes1{ 

foreach race in 0 1 {
*bstat the bootstarpped file with bounds
use vc_`outcome'_ygroup1_white`race'_I2_be, clear
qui bstat using vc_`outcome'_ygroup1_white`race'_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,12]
sca list N
set more off

*LATE_at
matrix blL3=b[1,147]'
matrix list blL3
matrix buL3=b[1,148..149]'
matrix list buL3

matrix VblL3=Vb[147,147]
matrix list VblL3

matrix VbuL3=Vb[148..149,148..149]
matrix list VbuL3


set seed 1989
CLR blL3 VblL3 buL3 VbuL3 N 100000 0.05
mat Llate3_at_95=e(Lstar)
mat list Llate3_at_95
mat Ulate3_at_95=e(Ustar)
mat list Ulate3_at_95
mat CILlate3_at_95=e(CIL)
mat list CILlate3_at_95
mat CIUlate3_at_95=e(CIU)
mat list CIUlate3_at_95

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.1
mat Llate3_at_90=e(Lstar)
mat list Llate3_at_90
mat Ulate3_at_90=e(Ustar)
mat list Ulate3_at_90
mat CILlate3_at_90=e(CIL)
mat list CILlate3_at_90
mat CIUlate3_at_90=e(CIU)
mat list CIUlate3_at_90


*This part compute the p-value of the bounds excluding 0 
local alpha=0.5
local alpha1000=`alpha'*1000 

CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'

local Llate3_at_`alpha1000'=Llate3_at_`alpha1000'[1,1]
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local Ulate3_at_`alpha1000'=Ulate3_at_`alpha1000'[1,1]
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Llate3_at_`alpha1000''>0 {

while `CILlate3_at_`alpha1000''>0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)	
      }
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ulate3_at_`alpha1000''<0 {

while `CIUlate3_at_`alpha1000''<0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)
      }
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}

*Generate variables needed for the figure 
*X-axis

gen GROUP=`i'

gen L_LATE=Llate3_at_95[1,1]
gen U_LATE=Ulate3_at_95[1,1]
gen CI_L_LATE_95=CILlate3_at_95[1,1]
gen CI_U_LATE_95=CIUlate3_at_95[1,1]
gen CI_L_LATE_90=CILlate3_at_90[1,1]
gen CI_U_LATE_90=CIUlate3_at_90[1,1]
gen pvalue=`pvalue'
gen eyt0=b[1,26]

keep GROUP L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue

save Figure_`outcome'_white`race'_delta_at, replace
     }
local i=`i'+2	 
}	 



local i=2

foreach outcome in $outcomes2{
foreach year in 1 3 4 5 {
*White Results

*Step 1. The crime LATE for the 1948-1952 white compliers 
use vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*P3: LATE_at
matrix blL3=b[1,131]'
matrix list blL3
matrix buL3=b[1,132..133]'
matrix list buL3

matrix VblL3=Vb[131,131]
matrix list VblL3

matrix VbuL3=Vb[132..133,132..133]
matrix list VbuL3


set seed 1989

*This part compute the p-value of the CI excluding 2SLS
local alpha=0.5
local alpha1000=`alpha'*1000 

CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'

local Llate3_at_`alpha1000'=Llate3_at_`alpha1000'[1,1]
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local Ulate3_at_`alpha1000'=Ulate3_at_`alpha1000'[1,1]
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Llate3_at_`alpha1000''>0 & `alpha'>0 {

while `CILlate3_at_`alpha1000''>0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)	
      }
display "the CI of the lower bound reject zero at the level of `pvalue'" 
   } 
else {
if `Ulate3_at_`alpha1000''<0 & `alpha'>0 {

while `CIUlate3_at_`alpha1000''<0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)
      }
display "the CI of the upper bound reject zero at the level of `pvalue'" 
   } 
}

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.05
mat Llate3_at_95=e(Lstar)
mat list Llate3_at_95
mat Ulate3_at_95=e(Ustar)
mat list Ulate3_at_95
mat CILlate3_at_95=e(CIL)
mat list CILlate3_at_95
mat CIUlate3_at_95=e(CIU)
mat list CIUlate3_at_95

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.1
mat Llate3_at_90=e(Lstar)
mat list Llate3_at_90
mat Ulate3_at_90=e(Ustar)
mat list Ulate3_at_90
mat CILlate3_at_90=e(CIL)
mat list CILlate3_at_90
mat CIUlate3_at_90=e(CIU)
mat list CIUlate3_at_90



*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'

gen L_LATE=Llate3_at_95[1,1]
gen U_LATE=Ulate3_at_95[1,1]
gen CI_L_LATE_95=CILlate3_at_95[1,1]
gen CI_U_LATE_95=CIUlate3_at_95[1,1]
gen CI_L_LATE_90=CILlate3_at_90[1,1]
gen CI_U_LATE_90=CIUlate3_at_90[1,1]
gen pvalue=`pvalue'
gen eyt0=b[1,10]

keep GROUP L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue

save Figure_`outcome'_yeargroup`year'_white1_delta_at, replace

*Nonwhite Results

*bstat the bootstarpped file with bounds
use vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*LATE_at
matrix blL3=b[1,595]'
matrix list blL3
matrix buL3=b[1,596..597]'
matrix list buL3

matrix VblL3=Vb[595,595]
matrix list VblL3

matrix VbuL3=Vb[596..597,596..597]
matrix list VbuL3

*This part compute the p-value of the CI excluding 2SLS
local alpha=0.5
local alpha1000=`alpha'*1000 

CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'

local Llate3_at_`alpha1000'=Llate3_at_`alpha1000'[1,1]
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local Ulate3_at_`alpha1000'=Ulate3_at_`alpha1000'[1,1]
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Llate3_at_`alpha1000''>0 & `alpha'>0 {

while `CILlate3_at_`alpha1000''>0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)	
      }
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ulate3_at_`alpha1000''<0 & `alpha'>0 {

while `CIUlate3_at_`alpha1000''<0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)
      }
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}


set seed 1989
CLR blL3 VblL3 buL3 VbuL3 N 100000 0.05
mat Llate3_at_95=e(Lstar)
mat list Llate3_at_95
mat Ulate3_at_95=e(Ustar)
mat list Ulate3_at_95
mat CILlate3_at_95=e(CIL)
mat list CILlate3_at_95
mat CIUlate3_at_95=e(CIU)
mat list CIUlate3_at_95

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.1
mat Llate3_at_90=e(Lstar)
mat list Llate3_at_90
mat Ulate3_at_90=e(Ustar)
mat list Ulate3_at_90
mat CILlate3_at_90=e(CIL)
mat list CILlate3_at_90
mat CIUlate3_at_90=e(CIU)
mat list CIUlate3_at_90

*Generate variables needed for the figure 
*X-axis

gen GROUP=`i'

gen L_LATE=Llate3_at_95[1,1]
gen U_LATE=Ulate3_at_95[1,1]
gen CI_L_LATE_95=CILlate3_at_95[1,1]
gen CI_U_LATE_95=CIUlate3_at_95[1,1]
gen CI_L_LATE_90=CILlate3_at_90[1,1]
gen CI_U_LATE_90=CIUlate3_at_90[1,1]
gen pvalue=`pvalue'
gen eyt0=b[1,474]

keep GROUP L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue

save Figure_`outcome'_yeargroup`year'_white0_delta_at, replace
    }
local i=`i'+2

     }
	 

local i=1

foreach outcome in $outcomes1 {
foreach year in 3 4 5 {
*White Bars

*Step 1. The crime LATE for the 1948-1952 white compliers 
use vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*P3: LATE_at
matrix blL3=b[1,131]'
matrix list blL3
matrix buL3=b[1,132..133]'
matrix list buL3

matrix VblL3=Vb[131,131]
matrix list VblL3

matrix VbuL3=Vb[132..133,132..133]
matrix list VbuL3


set seed 1989

*This part compute the p-value of the CI excluding 2SLS
local alpha=0.5
local alpha1000=`alpha'*1000 

CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'

local Llate3_at_`alpha1000'=Llate3_at_`alpha1000'[1,1]
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local Ulate3_at_`alpha1000'=Ulate3_at_`alpha1000'[1,1]
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Llate3_at_`alpha1000''>0 & `alpha'>0 {

while `CILlate3_at_`alpha1000''>0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)	
      }
display "the CI of the lower bound reject zero at the level of `pvalue'" 
   } 
else {
if `Ulate3_at_`alpha1000''<0 & `alpha'>0 {

while `CIUlate3_at_`alpha1000''<0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)
      }
display "the CI of the upper bound reject zero at the level of `pvalue'" 
   } 
}

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.05
mat Llate3_at_95=e(Lstar)
mat list Llate3_at_95
mat Ulate3_at_95=e(Ustar)
mat list Ulate3_at_95
mat CILlate3_at_95=e(CIL)
mat list CILlate3_at_95
mat CIUlate3_at_95=e(CIU)
mat list CIUlate3_at_95

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.1
mat Llate3_at_90=e(Lstar)
mat list Llate3_at_90
mat Ulate3_at_90=e(Ustar)
mat list Ulate3_at_90
mat CILlate3_at_90=e(CIL)
mat list CILlate3_at_90
mat CIUlate3_at_90=e(CIU)
mat list CIUlate3_at_90



*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'

gen L_LATE=Llate3_at_95[1,1]
gen U_LATE=Ulate3_at_95[1,1]
gen CI_L_LATE_95=CILlate3_at_95[1,1]
gen CI_U_LATE_95=CIUlate3_at_95[1,1]
gen CI_L_LATE_90=CILlate3_at_90[1,1]
gen CI_U_LATE_90=CIUlate3_at_90[1,1]
gen pvalue=`pvalue'
gen eyt0=b[1,10]

keep GROUP L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue

save Figure_`outcome'_yeargroup`year'_white1_delta_at, replace



*Nonwhite Bars

*Step 1. The crime LATE for the 1948-1952 white compliers 
use vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup`year'_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*P3: LATE_at
matrix blL3=b[1,595]'
matrix list blL3
matrix buL3=b[1,596..597]'
matrix list buL3

matrix VblL3=Vb[595,595]
matrix list VblL3

matrix VbuL3=Vb[596..597,596..597]
matrix list VbuL3

*This part compute the p-value of the CI excluding 2SLS
local alpha=0.5
local alpha1000=`alpha'*1000 

CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'

local Llate3_at_`alpha1000'=Llate3_at_`alpha1000'[1,1]
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local Ulate3_at_`alpha1000'=Ulate3_at_`alpha1000'[1,1]
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Llate3_at_`alpha1000''>0 & `alpha'>0 {

while `CILlate3_at_`alpha1000''>0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Llate3_at_`alpha1000'=e(Lstar)
mat list Llate3_at_`alpha1000'
mat CILlate3_at_`alpha1000'=e(CIL)
mat list CILlate3_at_`alpha1000'
local CILlate3_at_`alpha1000'=CILlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)	
      }
display "the CI of the lower bound reject zero at the level of `pvalue'" 
   } 
else {
if `Ulate3_at_`alpha1000''<0 & `alpha'>0 {

while `CIUlate3_at_`alpha1000''<0 & `pvalue'>=0.002 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'"
qui CLR blL3 VblL3 buL3 VbuL3 N 100000 `alpha'
mat Ulate3_at_`alpha1000'=e(Ustar)
mat list Ulate3_at_`alpha1000'
mat CIUlate3_at_`alpha1000'=e(CIU)
mat list CIUlate3_at_`alpha1000'
local CIUlate3_at_`alpha1000'=CIUlate3_at_`alpha1000'[1,1]
local pvalue=(`alpha'+0.001)
      }
display "the CI of the upper bound reject zero at the level of `pvalue'" 
   } 
}


set seed 1989
CLR blL3 VblL3 buL3 VbuL3 N 100000 0.05
mat Llate3_at_95=e(Lstar)
mat list Llate3_at_95
mat Ulate3_at_95=e(Ustar)
mat list Ulate3_at_95
mat CILlate3_at_95=e(CIL)
mat list CILlate3_at_95
mat CIUlate3_at_95=e(CIU)
mat list CIUlate3_at_95

CLR blL3 VblL3 buL3 VbuL3 N 100000 0.1
mat Llate3_at_90=e(Lstar)
mat list Llate3_at_90
mat Ulate3_at_90=e(Ustar)
mat list Ulate3_at_90
mat CILlate3_at_90=e(CIL)
mat list CILlate3_at_90
mat CIUlate3_at_90=e(CIU)
mat list CIUlate3_at_90

*Generate variables needed for the figure 
*X-axis

gen GROUP=`i'

gen L_LATE=Llate3_at_95[1,1]
gen U_LATE=Ulate3_at_95[1,1]
gen CI_L_LATE_95=CILlate3_at_95[1,1]
gen CI_U_LATE_95=CIUlate3_at_95[1,1]
gen CI_L_LATE_90=CILlate3_at_90[1,1]
gen CI_U_LATE_90=CIUlate3_at_90[1,1]
gen pvalue=`pvalue'
gen eyt0=b[1,474]

keep GROUP L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue

save Figure_`outcome'_yeargroup`year'_white0_delta_at, replace

    }
local i=`i'+2

     }
	 
/* Section 2. This section create panel figures in Figure 4 and Figure 5   */ 
* White 1948-1952 born 
use Figure_currentViolent_white1_delta_at, clear 
append using Figure_nonviolent_new_yeargroup1_white1_delta_at
append using Figure_violent_desistence_white1_delta_at 
append using Figure_nonviolent_desistance_yeargroup1_white1_delta_at


collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_1_4850, replace 

use Figure_6_1_4850, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100


twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -0.2(0.2)0.4, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (A) White Volunteers Born in 1948-1952") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_1_4852, replace 



* White 1950 born
use Figure_currentViolent_yeargroup3_white1_delta_at, clear 
append using Figure_nonviolent_new_yeargroup3_white1_delta_at
append using Figure_violent_desistence_yeargroup3_white1_delta_at 
append using Figure_nonviolent_desistance_yeargroup3_white1_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_1_1950, replace 

use Figure_6_1_1950, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100


twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -0.2(0.2)0.4, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (B) White Volunteers Born in 1950") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_1_1950, replace 


* White 1951 born
use Figure_currentViolent_yeargroup4_white1_delta_at, clear 
append using Figure_nonviolent_new_yeargroup4_white1_delta_at
append using Figure_violent_desistence_yeargroup4_white1_delta_at 
append using Figure_nonviolent_desistance_yeargroup4_white1_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_1_1951, replace 

use Figure_6_1_1951, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -0.2(0.2)0.4, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (A) White Volunteers Born in 1951") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_1_1951, replace 



*White 1952 born
use Figure_currentViolent_yeargroup5_white1_delta_at, clear 
append using Figure_nonviolent_new_yeargroup5_white1_delta_at
append using Figure_violent_desistence_yeargroup5_white1_delta_at 
append using Figure_nonviolent_desistance_yeargroup5_white1_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_1_1952, replace 

use Figure_6_1_1952, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -0.2(0.2)0.4, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (B) White Volunteers Born in 1952") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_1_1952, replace 



*Nonwhite 1948-1952 born 
use Figure_currentViolent_white0_delta_at, clear 
append using Figure_nonviolent_new_yeargroup1_white0_delta_at
append using Figure_violent_desistence_white0_delta_at 
append using Figure_nonviolent_desistance_yeargroup1_white0_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_0_4852, replace 

use Figure_6_0_4852, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -1(1)2, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (C) Nonwhite Volunteers Born in 1948-1952") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_0_4852, replace 



*Nonwhite 1950 born 
use Figure_currentViolent_yeargroup3_white0_delta_at, clear 
append using Figure_nonviolent_new_yeargroup3_white0_delta_at
append using Figure_violent_desistence_yeargroup3_white0_delta_at 
append using Figure_nonviolent_desistance_yeargroup3_white0_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_0_1950, replace 

use Figure_6_0_1950, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -1(1)3, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (D) Nonwhite Volunteers Born in 1950") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_0_1950, replace 


*Nonwhite 1951 born 
use Figure_currentViolent_yeargroup4_white0_delta_at, clear 
append using Figure_nonviolent_new_yeargroup4_white0_delta_at
append using Figure_violent_desistence_yeargroup4_white0_delta_at 
append using Figure_nonviolent_desistance_yeargroup4_white0_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_0_1951, replace 

use Figure_6_0_1951, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -1(1)3, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (C) Nonwhite Volunteers Born in 1951") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_0_1951, replace 



*White 1952 born 
use Figure_currentViolent_yeargroup5_white0_delta_at, clear 
append using Figure_nonviolent_new_yeargroup5_white0_delta_at
append using Figure_violent_desistence_yeargroup5_white0_delta_at 
append using Figure_nonviolent_desistance_yeargroup5_white0_delta_at

collapse (mean) L_LATE U_LATE CI_L_LATE_95 CI_U_LATE_95 CI_L_LATE_90 CI_U_LATE_90 eyt0 pvalue, by(GROUP)
save Figure_6_0_1952, replace 

use Figure_6_0_1952, clear
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname

gen PP_eyt0=eyt0*100 
gen PP_L_LATE=L_LATE*100
gen PP_U_LATE=U_LATE*100
gen PP_CI_L_LATE_95=CI_L_LATE_95*100
gen PP_CI_U_LATE_95=CI_U_LATE_95*100 
gen PP_CI_L_LATE_90=CI_L_LATE_90*100 
gen PP_CI_U_LATE_90=CI_U_LATE_90*100

twoway (rbar PP_U_LATE PP_L_LATE GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), /// 
ylabel( -1(1)3, labsize(small) grid glcolor(black) glwidth(medthick) glpattern(dot)) /// 
legend (order(1 "Effect Upper and Lower Bounds" 2 "95% CI" 3 "Mean Incarceration Rate of Nonveterans" 4 "90% CI"))  ///   
xtitle("")  /// 
title("Panel (D) Nonwhite Volunteers Born in 1952") /// 
graphregion(color(white)) ///
|| (rcap PP_CI_U_LATE_95 PP_CI_L_LATE_95 GROUP, msize(vlarge) lwidth(median) color(black)) /// 
|| (scatter PP_eyt0 GROUP, msymbol(dot) msize(large) mlw(medthick) color(black)) ///
|| (rcap PP_CI_U_LATE_90 PP_CI_L_LATE_90 GROUP, msize(vlarge) lwidth(median) color(black))

graph save Figure_6_0_1952, replace 


graph combine Figure_6_1_4852.gph Figure_6_1_1950.gph Figure_6_0_4852.gph Figure_6_0_1950.gph, rows(4) cols(1) iscale(0.6) ysize(20) xsize(12)

graph combine Figure_6_1_1951.gph Figure_6_1_1952.gph Figure_6_0_1951.gph Figure_6_0_1952.gph, rows(4) cols(1) iscale(0.6) ysize(20) xsize(12)






